package Vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import Controlador.Sistema;
import Negocio.PropietarioView;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaLoteCompuesto extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton jButton1;
	private JMenu jMenu1;
	private JLabel jLabel1;
	private JLabel jLabel6;
	private JButton jButton3;
	private JButton jButton2;
	private Vector <PropietarioView> prop;
	private JComboBox propiet;
	private Vector <Long> lotes;
	private JComboBox lot;
	private ArrayList <Long> l ;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaLoteCompuesto inst = new AltaLoteCompuesto();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AltaLoteCompuesto() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Alta Cereal Lote Simple");
			l = new ArrayList <Long>();
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Guardar");
				jButton1.setBounds(68, 93, 99, 21);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("Guardar.actionPerformed, event="+evt);
						int indice = propiet.getSelectedIndex()-1;
						PropietarioView p = prop.elementAt(indice);
						Sistema.getInstancia().AltaLoteCompuesto(p,l);
						dispose();
					}
				});
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Cancelar");
				jButton2.setBounds(190, 93, 92, 21);
			}
			{
				jButton3 = new JButton();
				getContentPane().add(jButton3);
				jButton3.setText("Agregar");
				jButton3.setBounds(247, 49, 53, 21);
				jButton3.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton3.actionPerformed, event="+evt);
						int indice = lot.getSelectedIndex()-1;
						l .add(lotes.elementAt(indice));
					}
				});
			}
			{
				jLabel6 = new JLabel();
				getContentPane().add(jLabel6);
				jLabel6.setText("Lotes");
				jLabel6.setBounds(49, 52, 38, 14);
			}
			{
				jLabel1 = new JLabel();
				jLabel1.setText("Propiertario");
				jLabel1.setBounds(12, 22, 81, 14);
			}
			{
				jMenu1 = new JMenu();
				getContentPane().add(jMenu1);
				getContentPane().add(jLabel1);
				jMenu1.setText("jMenu1");
			}
			{
				prop = new Vector <PropietarioView>();
				prop = Sistema.getInstancia().buscarPropietarios();
				//Armar texto
				Vector<String> nombres = new Vector<String>();
				nombres.add("  ");
				for (int i=0;i<prop.size();i++)
				{
					nombres.add(prop.elementAt(i).getNombre());
				}
				ComboBoxModel MineralesModel = new DefaultComboBoxModel(nombres);
				propiet = new JComboBox();
				getContentPane().add(propiet);
				propiet.setModel(MineralesModel);
				propiet.setBounds(105, 19, 112, 21);
			}
			{
				lotes = new Vector <Long>();
				lotes = Sistema.getInstancia().buscarLotes();
				//Armar texto
				Vector<String> nombres = new Vector<String>();
				nombres.add("  ");
				
				for (int i=0;i<lotes.size();i++)
				{
					nombres.add(String.valueOf(lotes.elementAt(i)));
				}
				
				ComboBoxModel MineralesModel = new DefaultComboBoxModel(nombres);
				lot = new JComboBox();
				getContentPane().add(lot);
				lot.setModel(MineralesModel);
				lot.setBounds(105, 49, 112, 21);
			}
			
			pack();
			this.setSize(503, 304);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	


}
